const mongoose = require("mongoose")

var Schema = mongoose.Schema


// 商品一级分类

var GoodsFirstClass = new Schema({
    classname: {
        type: String,
        required: true,
    },
    status: {
        type: String,
        default: "1"
    },
    icon: {
        type: String,
    },
    children: [
        {
            type: Schema.Types.ObjectId,
            ref: "goodsSecondClass"
        }
    ]
}, {
    timestamps: {
        createdAt: "addtime",
        updatedAt: "updatetime"
    }
})

//  商品二级分类
var GoodsSecondClass = new Schema({
    classname: {
        type: String,
        required: true,
    },
    status: {
        type: String,
        default: "1"
    },
    icon: {
        type: String,
    },
    beLong: {
        type: Schema.Types.ObjectId,
        ref: "goodsFirstClass"
    },
    children: [
        {
            type: Schema.Types.ObjectId,
            ref: "goodsSecondClass"
        }
    ]
}, {
    timestamps: {
        createdAt: "addtime",
        updatedAt: "updatetime"
    }
})

//  商品主图
var GoodsMain = new Schema({
    img: {
        type: String,
        required: true,
    },
    beLong: {
        type: Schema.Types.ObjectId,
        ref: "goods"
    }
    
}, {
    timestamps: {
        createdAt: "addtime",
        updatedAt: "updatetime"
    }
})

//  商品规格
var GoodsGuide = new Schema({
    name: {
        type: String,
        required: true,
    },
    guidePrice: {
        type: Number,
        required: true,
    },
    guideStock: {
        type: Number,
        required: true,
    },
    beLong: {
        type: Schema.Types.ObjectId,
        ref: "goods"
    }
    
}, {
    timestamps: {
        createdAt: "addtime",
        updatedAt: "updatetime"
    }
})


//  商品信息
var GoodsSchema = new Schema({
    // 商品标题
    title: {
        type: String,
        required: true
    },
    // 库存
    stock: {
        type:String,
        required: true
    },
    //  商品主图
    mainImage: {
        type: Array
    },
    // 商品详情图片
    ImageList: {
        type: String
    },
    // 商品规格
    guides: {
        type: Array
    },

    //  商品售价
    price: {
        type: Number,
        required:true
    },

    //  商品折扣
    sale: {
        type:Number,
        default: 0
    },

    // 一级分佣比例
    proportion: {
        type: Number,
        default: 0
    },
    // 二级分佣
    secproportion: {
        type:Number
    },
    // 商品是否上架
    status: {
        type: String,
        default: "1"
    },
    beLong: {
        type: Array
    }
}, {
    timestamps: {
        createdAt: "addtime",
        updatedAt: "updatetime"
    }
})

module.exports = {
    Goods: mongoose.model("goods", GoodsSchema),
    GoodsFirstClass: mongoose.model("goodsFirstClass", GoodsFirstClass),
    GoodsSecondClass: mongoose.model("goodsSecondClass", GoodsSecondClass),
    GoodsMain: mongoose.model("goodsMain", GoodsMain),
    GoodsGuide: mongoose.model("goodsGuide", GoodsGuide),
}